package com.xin.di.uav.common.exception;

import com.xin.di.uav.common.enums.ErrorEnum;

import java.text.MessageFormat;


/**
 * @author jianwen.lu
 * @version 1.0
 * @description 业务异常类
 * @date 2020-07-14 21:20
 * @since 1.8
 */
public class BusinessException extends RuntimeException {
    private ErrorEnum error;
    private String errDetail;
    private Object extraData;

    /**
     * 标准异常，并携带自定义数据
     *
     * @param error
     * @param errDetail
     */
    public BusinessException(ErrorEnum error, String errDetail) {
        this(error, errDetail, null);
    }

    public BusinessException(ErrorEnum error, Object... args) {

        this(error, MessageFormat.format(error.getErrMsg(), args));

        //this.error = error;
        //this.errDetail = msg;

    }

    /**
     * 自定义异常，使用预定义的的errCode和自定义message,且携带自定义数据
     *
     * @param error
     * @param errDetail
     * @param extraData
     */
    public BusinessException(ErrorEnum error, String errDetail, Object extraData) {
        super(null == errDetail ? error.getErrMsg() : errDetail);
        this.error = error;
        this.errDetail = errDetail;
        this.extraData = extraData;
    }
    public BusinessException(String message) {
        super(message);
    }
    public ErrorEnum getError() {
        return error;
    }

    public void setError(ErrorEnum error) {
        this.error = error;
    }

    public String getErrDetail() {
        return errDetail;
    }

    public void setErrDetail(String errDetail) {
        this.errDetail = errDetail;
    }

    public Object getExtraData() {
        return extraData;
    }

    public void setExtraData(Object extraData) {
        this.extraData = extraData;
    }
}
